<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
/**
* Facebook Class
*/
require_once 'config.php';
require_once(__ROOT__."/facebook/facebook.php");
class FacebookApi extends Facebook
{
    var $paramsp = "";
    function __construct() { 
        $config = array(
                'appId' => APP_ID,
                'secret' => APP_SECRET,
                'fileUpload' => true, // optional
                'allowSignedRequest' => true, // optional, but should be set to false for non-canvas apps
        );
        parent::__construct($config);

        $this->paramsp['scope'] = 'publish_stream, user_birthday, publish_actions, user_friends, status_update';
        $this->paramsp['redirect_uri'] = BASE_URL_USER;
    }

    function _error() {
        $loginUrl = $this->getLoginUrl($this->paramsp);
        exit("Loading ...<script>window.top.location.replace('$loginUrl');</script>");
    }

    function _redirectLogin() {
        $this->_error();
    }

    function _getMyUid() {
        $user_id = $this->getUser();
        if ($user_id == 0) {
            $this->_redirectLogin();
        }
        return $user_id;
    }

    function _getMyProfile() {
        $this->_getMyUid();

        $user_profile = $this->api('/me','GET');
        return $user_profile;
    }
}
?>